
#include "rtps/common/Locator.h"
#include "rtps/common/types.h"
#include "rtps/entities/WriterProxy.h"


inline void rtps_WriterProxy_construct(struct rtps_WriterProxy *writerProxy, const Guid_t *guid, const Locator *loc)
{
	memset(writerProxy, 0, sizeof(struct rtps_WriterProxy));
	
	writerProxy->remoteWriterGuid = *guid;
	//writerProxy->expectedSN = {0, 1};
  writerProxy->expectedSN.high = 0;
  writerProxy->expectedSN.low = 1;
	//writerProxy->ackNackCount = {1};
  writerProxy->ackNackCount.value = 1;
	writerProxy->hbCount.value = 0;
	writerProxy->remoteLocator = *loc;
}

// For now, we don't store any packets, so we just request all starting from
// the next expected
inline SequenceNumberSet rtps_WriterProxy_getMissing(struct rtps_WriterProxy *writerProxy, const SequenceNumber_t *firstAvail,
                             const SequenceNumber_t *lastAvail) {
  SequenceNumberSet set;
  /* ???? */
  if (rtps_SequenceNumber_t_operator_less(lastAvail, &writerProxy->expectedSN)) {
    set.base = writerProxy->expectedSN;
    set.numBits = 0;
  } else {
    set.numBits = 1;
    set.base = writerProxy->expectedSN;
    set.bitMap[0] = ((uint32_t)1) << 31;
  }
  (void)firstAvail;
  return set;
}

inline Count_t rtps_WriterProxy_getNextAckNackCount(struct rtps_WriterProxy *writerProxy) {
  const Count_t tmp = writerProxy->ackNackCount;
  ++(writerProxy->ackNackCount.value);
  return tmp;
}
